﻿#include "UnbindCommand.h"

#include "BindCommand.h"
#include "../../Modules/ModulesManager.h"

bool UnbindCommand_onExecute(const fast_io::vector<std::u8string>& args) {
	if (args.size() != 2)
		return false;
	if (args[1].empty())
		return false;

	if (args[1] == u8"all") {
		constexpr auto moduleCount = ModuleManager::getModuleCount();
		for (size_t i = 0; i < moduleCount; i++)
			ModuleManager::moduleList[i]->setKeybind(0);
		switch (SettingManager::languageget) {
		case 0:
		default:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"All modules were unbound successfully!");
			break;
		case 1:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"所有模块取消绑定成功！");
			break;
		case 2:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"所有模塊取消綁定成功！");
			break;
		case 3:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"すべてのモジュールが正常にバインド解除されました！");
			break;
			std::unreachable();
		}

		return true;
	}

	auto modOpt = ModuleManager::getModuleByName(args[1]);
	if (modOpt == nullptr) {
		switch (SettingManager::languageget) {
		case 0:
		default:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::RED,
											 u8"Moudle ",
											 args[1],
											 u8" does not exist!");
			break;
		case 1:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::RED,
											 u8"模块 ",
											 args[1],
											 u8" 不存在！");
			break;
		case 2:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::RED,
											 u8"模塊 ",
											 args[1],
											 u8" 不存在！");
			break;
		case 3:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::RED,
											 u8"モジュール ",
											 args[1],
											 u8" が存在しません！");
			break;
			std::unreachable();
		}
		return true;
	} else {
		modOpt->setKeybind(0);

		switch (SettingManager::languageget) {
		case 0:
		default:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"Successfully unbound module ",
											 args[1]);
			break;
		case 1:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"模块 ",
											 args[1],
											 u8" 取消绑定成功！");
			break;
		case 2:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"模塊 ",
											 args[1],
											 u8" 取消綁定成功！");
			break;
		case 3:
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"モジュール ",
											 args[1],
											 u8" が正常にバインド解除されました！");
			break;
			std::unreachable();
		}

		return true;
	}
}

ICommand UnbindCommand{u8"unbind",
					 u8".unbind [<module>, all]",
					 {u8"Unbind modules", u8"取消绑定模块", u8"取消綁定模塊", u8"モジュールのアンバインド"},
					 {},
					 fast_io::vector<aliasList_struct>{},  // If empty must use fast_io::vector<aliasList_struct>{}
					 &BindCommand_onInit,
					 &UnbindCommand_onExecute};